#define Aout A0 //光
#include <dht11.h>//温湿度
int temp = 0; //临时变量，存储A0读取的数据
#define DHT11PIN 2 //定义D2为数据输出口
dht11 DHT11;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//定义波特率
  pinMode(Aout, INPUT);//定义A0为INPUT模式
   pinMode(DHT11PIN,OUTPUT);
   pinMode(4,OUTPUT);
   digitalWrite(4,LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  temp = analogRead(Aout); //读取A0的模拟数据
  
  String a=String(temp);
  int chk = DHT11.read(DHT11PIN);                 //将读取到的值赋给chk
int tem=(float)DHT11.temperature;               //将温度值赋值给tem
int hum=(float)DHT11.humidity;                   //将湿度值赋给hum
Serial.print("Tempeature:");                        //打印出Tempeature:
Serial.print(tem);                                     //打印温度结果
Serial.println("°c"); 
Serial.print("Humidity:");                            //打印出Humidity:
Serial.print(hum);                                     //打印出湿度结果
Serial.println("%");                                  //打印出%
Serial.println(""); 
//  Serial.println(" light:"+a); //串口输出temp的数据
   
  delay(500);  //延时500毫秒
  if(temp<300){
    digitalWrite(4,HIGH);
    delay(500);
    digitalWrite(4,LOW);
    }
    if(temp>300){
      digitalWrite(4,LOW);
      }
}
